﻿@page "/users"
@using GMS.NET.Web.Components.Pages.Systems.Users.Shared
@using GMS.NET.Dto.System.Users.Shared
@using GMS.NET.Dto.System.Users.Enums
@attribute [TabItemOption(Text = "用户管理")]

<Card IsShadow="true" HeaderText="用户管理">
    <BodyTemplate>
            <Table TItem="UsersData" IsBordered="true" IsStriped="true" IndentSize="8" HeaderStyle="@TableHeaderStyle.Light"
                    OnQueryAsync="@OnQueryAsync" ShowToolbar="true" ShowExtendButtons="true" 
                   OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync" ShowEditButton="false" EditDialogIsDraggable="true"
                   AddModalTitle="新增用户" EditModalTitle="编辑用户" ShowEmpty="true" IsPagination="true" IsMultipleSelect="true"
                   PageItemsSource="@(new int[] { 20, 40, 80, 100 })" ShowExportButton="true" OnExportAsync="OnExportAsync"
                   SearchMode="SearchMode.Top" ShowSearch="true" ShowSearchText="false" CustomerSearchModel="@usersSearchModel"
                   @ref="Table">
                <TableToolbarTemplate>
                    <TableToolbarButton TItem="UsersData"
                                        Color="Color.Primary"
                                        Icon="fas fa-fw fa-file-export"
                                        Text="导入"
                                        IsAsync OnClickCallback="@OpenUploadExcel" />
                </TableToolbarTemplate>
                <TableColumns>
                    <TableColumn @bind-Field="@context.User_Name" Sortable />
                    <TableColumn @bind-Field="@context.User_Account" />
                    <TableColumn @bind-Field="@context.User_RoleName" />
                    <TableColumn @bind-Field="@context.User_CusName" />
                    <TableColumn @bind-Field="@context.User_Phone" />
                    <TableColumn @bind-Field="@context.User_Email" />
                    <TableColumn @bind-Field="@context.User_Status">
                        <Template Context="value">
                            <Switch Value="@(value.Value==User_Status.normal)" ValueChanged="(val)=>UserStatusOnChanged(val,value.Row.Id)"
                                    OnColor="Color.Success" OnText="正常" OffText="禁用"></Switch>
                        </Template>
                    </TableColumn>
                    <TableColumn @bind-Field="@context.User_Type" />
                    <TableColumn @bind-Field="@context.User_Remark" />
                </TableColumns>
                <EditTemplate Context="value">
                    <UsersForm Context="value" />
                </EditTemplate>
                <CustomerSearchTemplate>
                    @if (context is UsersSearchModel model)
                    {
                        <UsersSearch @bind-Value="@model" />
                    }
                </CustomerSearchTemplate>
                <ExportButtonDropdownTemplate Context="ExportContext">
                    <div class="dropdown-item" @onclick="ExportContext.ExportAsync">
                        <i class="fa-regular fa-file-excel"></i>
                        <span>Excel-xlsx</span>
                    </div>
                </ExportButtonDropdownTemplate>
            </Table>
    </BodyTemplate>
</Card>

<ImportExcel  ModalChanged="ModalChanged" ModelName="用户信息导入" ExcelTempName="用户导入模板" 
             DownExcelTempUrl="@("api/users/excel-temp")" DataCheckUrl="@("api/users/users-data-check")" 
             DataImportUrl="@("api/users/users-data-import")"></ImportExcel>

@code{
    private void ModalChanged(Modal modal)
    {
        UserExcelModel = modal;
    }
}